$(document).ready(function () {

    /***等待图****/
    var opts = {
        lines: 9, // The number of lines to draw
        length: 0, // The length of each line
        width: 12, // The line thickness
        radius: 43, // The radius of the inner circle
        scale: 1.05, // Scales overall size of the spinner
        corners: 1, // Corner roundness (0..1)
        color: '#01CBE9', // CSS color or array of colors
        fadeColor: 'transparent', // CSS color or array of colors
        speed: 1, // Rounds per second
        rotate: 0, // The rotation offset
        animation: 'spinner-line-fade-quick', // The CSS animation name for the lines
        direction: 1, // 1: clockwise, -1: counterclockwise
        zIndex: 2e9, // The z-index (defaults to 2000000000)
        className: 'spinner', // The CSS class to assign to the spinner
        top: '34%', // Top position relative to parent
        left: '50%', // Left position relative to parent
        shadow: '0 0 1px transparent', // Box-shadow for the lines
        position: 'absolute' // Element positioning
    };

    var target = document.getElementById('spin');
    var spinner = new Spinner(opts).spin(target);


    var
        groupCommentTop = '967',
        groupComment = '',
        response = '',
        pro = '',
        listCurrentPage = 1,

        Request = new searchUrl(),//地址参数化。方法来自base.jsx
        groupId = Request.groupId,           //productid的
        userInfo = getUserInfo(),  //获取用户信息，主要用于对管理员的处理
        d = getPlatform();          //获取的设备信息


    /****************************社区资料*********************************/

    getgroupinfo(groupId);

    function getgroupinfo(groupId) {
        myAjaxFunc({
            url: community + "getGroupItself",
            type: 'get',
            dataType: 'json',
            data: {id: groupId, platform: "pc/type:" + d},
            mySuccess: function (data) {
                if (isResponseSuccess('success', data)) {
                    console.log(data)
                    var group_name = data.data.group.name;
                    $('#group_name').text(group_name);
                    $('#groupNameList').text(group_name);
                    $('#groupLogo').attr('src', geturlimg + data.data.group.logoUrl);


                    $('#productRe').attr('href','loansDetail.html?id='+data.data.group.productId);

                    $('#groupSendPost').attr('href','userSendPost.html?groupId='+data.data.group.id+'&groupName='+data.data.group.name);
                    $('#sendPost').attr('href','userSendPost.html?groupId='+data.data.group.id+'&groupName='+data.data.group.name);




                    var producyid = data.data.group.productId;
                    if (notNull(producyid)) {
                        $('#group_name1').text(group_name);
                        sessionStorage.setItem('productId', producyid);
                    } else {
                        $('#goto_product').hide()
                    }

                }
                else {

                }
            }
        });
    }

    /****************************社区帖子*********************************/


    let indexGroupPostList= $("#productGroupListInner");


    function getcommunity(listCurrentPage) {
        myAjaxFunc({
            url: community + "getPagePost",
            type: 'post',
            dataType: 'json',
            data: {groupId: groupId, listCurrentPage: listCurrentPage},
            mySuccess: function (data) {
                if (isResponseSuccess('success', data)) {

                    $('#spin').fadeOut();
                    $('main').fadeIn();

                    let postData = isResponseSuccess('getdata', data);
                    postData.list.roles = set_roles();   //配置管理员信息
                    postData.list.listCurrentPage = postData.extra.listCurrentPage;  //配置当前页
                    postData.list.geturl = geturlimg;     //配置图片加载地址
                    let leng = postData.list.length;

                    if(leng<0){
                        return
                    }

                    for (let i = 0; i < leng; i++) {
                        let imgList = '';
                        let imgUrl = postData.list[i].imgUrls;
                        if (notNull(imgUrl)) {
                            imgList = postData.list[i].imgUrls.split(',');
                        }
                        postData.list[i].imgUrls = imgList;
                        postData.list[i].textContentShort = html_encode(postData.list[i].textContentShort);

                    }


                    //配置图片为数组

                    let pageInfo = postData.extra,
                        allpage = pageInfo.listPageCount, //总页数
                        atpage = pageInfo.listCurrentPage; //当前页数

                    console.log(postData);

                    var html = template('groupItem-post-list-template', postData);

                    indexGroupPostList.empty().append(html);

                    setTimeout(showPri(), 200);//返回显示点赞数据

                    creationPage(allpage,atpage);



                    /*******点击图片********/

                    changeImg();//更改图片样式
                }
            }
        });
    }



    function creationPage(allpage,atpage) {

        Page({
            num:allpage,			//页码数
            startnum:atpage,		//指定页码
            elem:$('#page'),		//指定的元素
            callback:function(n){	//回调函数
                getcommunity(n)
            }
        });
    }

    getcommunity(listCurrentPage)

    /****************************侧边栏最新贷款*********************************/

    sidebarfn('sidebarProduct','.NewLoansProductList');

    /****************************首页侧边栏热门帖子*********************************/

    sidebarfn('sidebarPost','#groupItemHotLoansList');



    function changeImg() {
        // var _imga = $('.postImg img');
        // _imga.load(function () {
        //     var Imgheight = $(this).height();
        //     var ImgWidth = $(this).width();
        //     if (Imgheight > ImgWidth) {
        //         $(this).parent().addClass('list_c').removeClass('list_a');
        //     }
        // });

        var _imgb = $('.postImg img');
        _imgb.load(function () {
            var Imgheight = $(this).height();
            var ImgWidth = $(this).width();
            if (Imgheight > ImgWidth) {
                $(this).addClass('forWidth')
            } else {
                $(this).addClass('forHeight')
            }

        })


    }

    changeImg()
    var groupCommentTop=980;

    $(document).scroll(function () {
        let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
            , che = document.documentElement.scrollHeight - (document.documentElement.clientHeight + scrollTop);


        var rightboxtx=getDistance( $('.leftGroupPost')).right;
        var bottomboxtx=getDistance( $('.leftGroupPost')).bottom;
        // var topboxtx=getDistance( $('.hotLoanInnerRightBox')).top;
        //
        // console.log('topboxtx'+groupCommentTop);
        // console.log('bottomboxtx'+bottomboxtx);

        console.log(scrollTop)

        if(scrollTop>groupCommentTop){
            $('.hotLoanInnerRightBox').addClass('fixRight');
            $('.hotLoanInnerRightBox').css({'right':rightboxtx-340+'px'})
        }else {
            $('.hotLoanInnerRightBox').removeClass('fixRight');

        }

        if(bottomboxtx<-10){
            $('.hotLoanInnerRightBox').css({'right':rightboxtx-340+'px'})
            $('.hotLoanInnerRightBox').show();
            $('.hotLoanInnerRightBox').removeClass('positionBottom');

        }else {

            $('.hotLoanInnerRightBox').removeClass('fixRight').addClass('positionBottom');



        }


    });
    /*END*/

    // $(".hotLoanInnerRightBox").pin();





});

